package jukebox.model.freeboard;

import java.util.List;

import javax.annotation.Resource;

import jukebox.model.common.BoardVO;
import jukebox.model.common.CommentVO;
import jukebox.model.common.ListVO;
import jukebox.model.common.PagingBean;
import jukebox.model.freecomment.FreeCommentDAO;

import org.springframework.stereotype.Service;


@Service
public class FreeBoardServiceImpl implements FreeBoardService {
	@Resource(name="freeBoardDAOImpl")
	private FreeBoardDAO freeBoardDAO;
	
	@Override
	public void freeWriteContent(BoardVO bvo) {
		freeBoardDAO.freeWriteContent(bvo);
	}
	
	@Override
	public BoardVO freeFindContentByNo(int no) {
		return freeBoardDAO.freeFindContentByNo(no);
	}

	@Override
	public void freeUdateContent(BoardVO bvo) {
		freeBoardDAO.freeUdateContent(bvo);
	}

	@Override
	public void freeDeleteContent(int no) {
		freeBoardDAO.freeDeleteContent(no);
	}

	@Override
	public void freeUpdateHit(int no) {
		freeBoardDAO.freeUpdateHit(no);		
	}
	
	//제목으로 검색된 리스트
	@Override
	public ListVO<BoardVO> getContentListByTitlePerPage(int nowPage,String title) {
		ListVO vo = null;		
		//PagingBean을 생성해준다.
				//freeBoardDAO.freeContentCountByTitle(title) 제목으로 검색된 게시물 수
				//현재 페이지 nowPageNo
				PagingBean pb = new PagingBean(freeBoardDAO.freeContentCountByTitle(title),nowPage,title);//int totalContents, int nowPage,String title
		//현재페이지에 맞는 게시물정보를 가져온다.
				System.out.println(pb);			
		List<BoardVO> list = freeBoardDAO.getContentListByTitlePerPage(pb); //page에 해당하는 게시물들을 조회
		System.out.println(list);
		vo = new ListVO(list,pb);//ArrayList<BoardVO> list, PagingBean pagingBean
		return vo;
	}

	@Override
	public ListVO<BoardVO> getContentListPerPage(int nowPage) {
		ListVO vo = null;		
		//PagingBean을 생성해준다.
				//boardDAO.ContentCount() 전체 페이지 수
				//현재 페이지 nowPageNo
				PagingBean pb = new PagingBean(freeBoardDAO.freeContentCount(),nowPage);//int totalContents, int nowPage
		//현재페이지에 맞는 게시물정보를 가져온다.
				System.out.println(pb);
		List<BoardVO> list = freeBoardDAO.getContentListPerPage(pb); //page에 해당하는 게시물들을 조회
		System.out.println(list);
		vo = new ListVO(list,pb);//ArrayList<BoardVO> list, PagingBean pagingBean
		
		return vo;
	}

	
}
